package com.example.dllo.exe.me;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.exe.R;
import com.example.dllo.exe.fengzhuang.NetTool;
import com.example.dllo.exe.bean.SQLGongLueBean;

import java.util.ArrayList;

/**
 * code is far away from bug with the animal protecting
 * <p>
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃永无BUG！  凯哥 祝你一路顺风
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 */
public class MeGongLueAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<SQLGongLueBean> sqlGongLueBean;
    private ItemOnClick itemonClick;

    public void setItemonClick(ItemOnClick itemonClick) {
        this.itemonClick = itemonClick;
    }

    public  interface ItemOnClick{
        void  ItemOnclick(int pos);
    }
    public MeGongLueAdapter(Context context) {
        this.context = context;
    }

    public void setSqlGongLueBean(ArrayList<SQLGongLueBean> sqlGongLueBean) {
        this.sqlGongLueBean = sqlGongLueBean;
        notifyDataSetChanged();
    }

    public void deletePos(int pos){
        sqlGongLueBean.remove(pos);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return sqlGongLueBean!=null?sqlGongLueBean.size():0;
    }

    @Override
    public SQLGongLueBean getItem(int i) {
        return sqlGongLueBean.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder=null;

        LayoutInflater inflater=LayoutInflater.from(context);
        if (view==null){
           view= inflater.inflate(R.layout.megngluelvlayout,null);
            viewHolder=new ViewHolder(view);
            view.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) view.getTag();
        }

            viewHolder.textViewname.setText(sqlGongLueBean.get(i).getName());
            viewHolder.textViewtitle.setText(sqlGongLueBean.get(i).getTitle());
            viewHolder.imageViewphoto.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    itemonClick.ItemOnclick(i);
                }
            });
          NetTool netTool=new NetTool();
        netTool.getImage(sqlGongLueBean.get(i).getUrl(),viewHolder.imageViewphoto);


        return view;
    }
    public  class  ViewHolder{
        TextView textViewtitle;
        TextView textViewname;
        ImageView imageViewphoto;
        public ViewHolder(View view){
            textViewtitle= (TextView) view.findViewById(R.id.title_text);
            textViewname= (TextView) view.findViewById(R.id.name_text);
            imageViewphoto= (ImageView) view.findViewById(R.id.photo_image);

        }
    }
}
